<!DOCTYPE html>
<html lang="en" xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>

<div id="app">
  <cpn></cpn>
  <cpn></cpn>
  <cpn ref="aaa"></cpn>
  <cpn></cpn>
  <button v-on:click="btnClick">按钮</button>
</div>

<template id="cpn">
  <div>我是一个子组件</div>
</template>

<script src="../js/vue.js"></script>
<script>
  const app = new Vue({
    el: '#app',
    data: {
      message: 'Rae是我儿子！'
    },
    methods: {
      btnClick: function () {
        // 1.$children
        // console.log(this.$children);
        // for (let c of this.$children) {
        //   c.showMessage();
        //   console.log(c.name)
        // }

        //2.$refs => 对象类型，默认是一个空的对象 ref='bbb'
        console.log(this.$refs.aaa);
      }
    },
    components: {
      cpn: {
        template: '#cpn',
        data: function () {
          return {
            name: '我是子组件的name'
          }
        },
        methods: {
          showMessage() {
            console.log('showMessage');
          }
        }
      }
    }
  })
</script>

</body>
</html>